﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using CustomsSystem.BLL;
using CustomsSystem.Model;
using Maticsoft.Common;
namespace WEB.T_document
{
    public partial class modelView : System.Web.UI.Page
    {
        CustomsSystem.BLL.info_document DM = new CustomsSystem.BLL.info_document();
        CustomsSystem.BLL.info_documentMastert BLDM = new CustomsSystem.BLL.info_documentMastert();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = BLDM.GetAllList();
                DropDownList1.DataTextField = "docViewName";
                DropDownList1.DataValueField = "docViewID";
                DropDownList1.DataBind();
                if (DropDownList1.SelectedValue !="")
                {
                    gvView.DataSource = DM.GetList("docViewID=" + DropDownList1.SelectedValue);
                    gvView.DataBind();
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("modelset.aspx");
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvView.DataSource = DM.GetList("docViewID=" + DropDownList1.SelectedValue);
            gvView.DataBind();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedValue != "")
            {
                int docviewid = Convert.ToInt32(DropDownList1.SelectedValue);
                if (DM.Delete(docviewid))
                {
                }
                else
                    return;
                if (BLDM.Delete(docviewid))
                {
                }
                else
                    return;

                MessageBox.Show(this, "删除成功!");

                DropDownList1.DataSource = BLDM.GetAllList();
                DropDownList1.DataTextField = "docViewName";
                DropDownList1.DataValueField = "docViewID";
                DropDownList1.DataBind();
                if (DropDownList1.SelectedValue != "")
                {
                    gvView.DataSource = DM.GetList("docViewID=" + DropDownList1.SelectedValue);
                    gvView.DataBind();
                }
                else
                {
                    gvView.DataSource = null;
                    gvView.DataBind();
                }
            }
            else
            {
                MessageBox.Show(this, "没有模板，请添加!");
            }
        }
    }
}